/**
 * Created by bman on 17-4-6.
 */
import { connect } from 'react-redux'
import CourseFilesEdit from "../../components/admin/CourseFilesEdit/CourseFilesEdit.jsx"
import {getCourseList,searchCourse,sortCourseList,SORT,filterCourse,changePage,selectCourse,move,addCourse,delFile} from "../../actions/admin/course_edit_actions.js"

const mapDispatchToProps = (dispatch) => {
    return {
        refresh : (filter,courseId) => {
            filter = filter || "ALL"
            dispatch(getCourseList(courseId))
        },
        init : (courseId) => {
            dispatch(getCourseList(courseId))
        },
        sort : (sortIdx,sortFlag) => {
            dispatch(sortCourseList(sortIdx,sortFlag))
        },
        search : (searchText) => {
            dispatch(searchCourse(searchText))
        },
        filter : (filterName) => {
            dispatch(filterCourse(filterName))
        },
        changePage : (page,limit) => {
            dispatch(changePage(page,limit))
        },
        selectCourse : (course) => {
            dispatch(selectCourse(course))
        },
        move : (direction,course) => {
            dispatch(move(direction,course))
        },
        addCourse : (course,courseId) => {
            dispatch(addCourse(course,courseId))
        },
        delFile : (id) => {
            dispatch(delFile(id))
        }
    }
}

const mapStateToProps = (state,ownProps) => {
    const {courseEdit} = state
    return {
        courses : courseEdit.courses,
        totalCount : courseEdit.cachedCourses.length,
        cachedCourses : courseEdit.cachedCourses,
        page : courseEdit.page,
        limit : courseEdit.limit,
        selectedCourses : courseEdit.selectedCourses
    }
}

const AdminCourseCtrlContainer = connect(
    mapStateToProps,
    mapDispatchToProps
)(CourseFilesEdit)

export default AdminCourseCtrlContainer